//
//  GridPersonnelListTableViewCell.swift
//  grid-ios-app
//
//  Created by yanlu on 2024/4/2.
//

import UIKit
import SnapKit

class GridPersonnelListTableViewCell: UITableViewCell {

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        setupLayouts()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    var listModel :GridPersonnelCellModel? {
        didSet {
            titleLabel.text = listModel?.name ?? ""
            messageLabel.text = listModel?.gridModel.name ?? ""
            phoneLabel.text = listModel?.phoneNum ?? ""
        }
    }
    
    func setupLayouts() {
        
        titleLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(10)
            make.top.equalToSuperview().offset(15)
            make.height.equalTo(20)
            make.right.equalTo(phoneLabel.snp.left).offset(-10).priority(.medium)

        }
        titleLabel.setContentHuggingPriority(.defaultHigh, for: .horizontal)

        phoneLabel.snp.makeConstraints { (make) in
            make.left.equalTo(titleLabel.snp.right).offset(10).priority(.medium)
            make.right.equalToSuperview().offset(-10)
            make.top.equalTo(titleLabel.snp.top)
            make.height.equalTo(20)
        }
        
        messageLabel.snp.makeConstraints { (make) in
            make.left.equalTo(titleLabel.snp.left)
            make.right.equalTo(phoneLabel.snp.right)
            make.top.equalTo(titleLabel.snp.bottom).offset(2)
            make.height.equalTo(18)
        }
        
        lineView.snp.makeConstraints { (make) in
            make.bottom.left.right.equalToSuperview()
            make.height.equalTo(1)
        }
    }
    
    private lazy var lineView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor(hex6: 0xF1F1F1)
        contentView.addSubview(view)
        return view
    }()
    
    private lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.backgroundColor = .clear
        label.textColor = UIColor(hex6:0x404040)
        label.font = Theme.Font.size(16)
        label.text = ""
        contentView.addSubview(label)
        return label
    }()
    
    private lazy var phoneLabel: UILabel = {
        let label = UILabel()
        label.backgroundColor = .clear
        label.textColor = UIColor(hex6:0x404040)
        label.font = Theme.Font.size(13)
        label.text = ""
        contentView.addSubview(label)
        return label
    }()
    
    private lazy var messageLabel: UILabel = {
        let label = UILabel()
        label.textColor = UIColor(hex6:0x404040)
        label.font = Theme.Font.size(13)
        label.text = ""
        contentView.addSubview(label)
        return label
    }()
    

}

class  GridPersonnelListHeaderView: UIView {
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
        setupUI()
    }
    
    private func setupUI() {
        titleLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(10)
            make.centerY.equalToSuperview()
            make.height.equalTo(20)
            make.width.equalTo(60)
        }
        
        numLabel.snp.makeConstraints { (make) in
            make.left.equalTo(titleLabel.snp.right).offset(10)
            make.right.equalToSuperview().offset(-10)
            make.centerY.equalToSuperview()
            make.height.equalTo(20)
        }
    }
    
    private lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.textColor = UIColor(hex6:0x404040)
        label.font = Theme.Font.size(16)
        label.text = "全部"
        label.backgroundColor = .clear
        label.textAlignment = .left
        addSubview(label)
        return label
    }()
    
    lazy var numLabel: UILabel = {
        let label = UILabel()
        label.textColor = UIColor(hex6:0x404040)
        label.font = Theme.Font.size(16)
        label.text = "人员总数：100"
        label.textAlignment = .right
        addSubview(label)
        return label
    }()
}
